package flc.ast.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.stark.picselect.entity.SelectMediaEntity;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.utils.TimeUtil;

public class SelVideoShowAdapter extends StkProviderMultiAdapter<SelectMediaEntity> {

    public SelVideoShowAdapter() {
        addItemProvider(new StkSingleSpanProvider(66));
        addItemProvider(new SelVideoShowProvider());
    }

    private boolean isVideo = false;

    public void setVideo(boolean video) {
        isVideo = video;
    }

    private class SelVideoShowProvider extends BaseItemProvider<SelectMediaEntity> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_sel_video_show;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, SelectMediaEntity bean) {
            if (TextUtils.isEmpty(bean.getPath())) {
                baseViewHolder.getView(R.id.llSelVideoShowItem).setVisibility(View.INVISIBLE);
            } else {
                baseViewHolder.getView(R.id.llSelVideoShowItem).setVisibility(View.VISIBLE);
                Glide.with(getContext()).load(bean.getPath())
                        .into((ImageView) baseViewHolder.getView(R.id.ivSelVideoShowItemImg));
                if (isVideo) {
                    baseViewHolder.getView(R.id.tvSelVideoShowItemDuration).setVisibility(View.VISIBLE);
                    baseViewHolder.setText(R.id.tvSelVideoShowItemDuration, TimeUtil.getMmss(bean.getDuration()));
                } else {
                    baseViewHolder.getView(R.id.tvSelVideoShowItemDuration).setVisibility(View.GONE);
                }
            }
        }
    }

}
